Skip to content

ENH: Add lazy copy to to_timestamp and to_period #50575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 11, 2023

Conversation

phofl
Copy link
Member

@phofl phofl commented Jan 4, 2023

@phofl phofl changed the title ENH: Add lazy copy for swapaxes no op ENH: Add lazy copy to to_timestamp and to_period Jan 4, 2023
@jorisvandenbossche jorisvandenbossche added this to the 2.0 milestone Jan 5, 2023
new_values = self._values
if copy:
new_values = new_values.copy()
new_obj = self.copy(deep=copy)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this copy after the index isinstance check?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved, kept the df as is to keep it consistent with the previous behavior

self, method="to_timestamp"
)
setattr(new_obj, "index", new_index)
return new_obj
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not fully sure, but we might want to keep the __finalize__ call? (although of course not a new object was constructed here, that already happened now in the copy() call)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see this is how it is done for the DataFrame implementation, so that's probably OK then

return self._constructor(new_values, index=new_index).__finalize__(
self, method="to_timestamp"
)
setattr(new_obj, "index", new_index)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the reason not to use new_obj.index = new_index for performance?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see this is how it is done for the DataFrame implementation

@jorisvandenbossche jorisvandenbossche merged commit aa789ea into pandas-dev:main Jan 11, 2023
@phofl phofl deleted the to_timestamp branch January 12, 2023 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants